<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('凭证头列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li >
								<label>凭证状态： </label><select name="pzzt" id="pzzt">
								    <option value="">全部</option>
									<option value="1">待审</option>
									<option value="2">已审</option>
									<option value="3">记帐</option>
								</select>
							</li>
                            <li>
								<label>核算年度：</label>
								<select name="nd" id="nd">
									<option th:each="nd : ${ndlist}" th:text="${nd}" th:value="${nd}" th:selected="${nd==year}"> </option>
								</select>
							</li>
                            <li >
								<label>核算期间： </label><select name="yf" id="yf">
								    <option th:each="yf : ${yflist}" th:text="${yf}" th:value="${yf}" th:selected="${yf==term}"></option>
								</select>
							</li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="add()" shiro:hasPermission="system:pzto:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="edit()" shiro:hasPermission="system:pzto:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger single disabled" onclick="remove()" shiro:hasPermission="system:pzto:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                 
                <a class="btn btn-success single disabled" onclick="singleaccount()" shiro:hasPermission="system:pzto:account">
                    <i class="fa fa-check"></i> 审核记账
                </a>
                <a class="btn btn-success single disabled" onclick="singleunaccount()" shiro:hasPermission="system:pzto:unaccount">
                    <i class="fa fa-close"></i>撤销记账
                </a>
                <a class="btn btn-success" onclick="checkbreak()" shiro:hasPermission="system:pzto:checkbreak">
                    <i class="fa fa-wrench"></i>断号检查
                </a>
                <a class="btn btn-success" onclick="editpzbrq()" shiro:hasPermission="system:pzto:edtpzsj">
                    <i class="fa fa-user-plus"></i>修改时间
                </a>
                <a class="btn btn-success" onclick="bataccount()" shiro:hasPermission="system:pzto:bataccount">
                    <i class="fa fa-check-square"></i>批量记账
                </a>
                <a class="btn btn-success" onclick="batunaccount()" shiro:hasPermission="system:pzto:batunaccount">
                    <i class="fa fa-share-square"></i>批量反记账
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:pzto:export">
                    <i class="fa fa-download"></i> 导出
                </a>
               
            </div>
            <div class="col-sm-12 select-table">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('system:pzto:edit')}]];
        var removeFlag = [[${@permission.hasPermi('system:pzto:remove')}]];
        var prefix = ctx + "system/pzto";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "凭证头",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'pztxh',
                    title: '凭证头序号',
                    visible: false
                },
                {
                    field: 'nd',
                    title: '年度'
                },
                {
                    field: 'yf',
                    title: '月份'
                },{
                    field: 'rq',
                    title: '日期'
                },
                {
                    field: 'pzbh',
                    title: '凭证编号'
                },/*
                {
                    field: 'zy',
                    title: '摘要'
                },*/
               
                {
                    field: 'zd',
                    title: '制单'
                },
                {
                    field: 'sh',
                    title: '审核'
                },
                {
                    field: 'pzzt',
                    title: '凭证状态 ',
		        	formatter: function (value, row, index) {
		        		return statuspzzt(row);
		        	}
                },
                {
                    field: 'pzlb',
                    title: '凭证类别',
		        	formatter: function (value, row, index) {
		        		return statuspzlb(row);
		        	}
                },
                {
                    field: 'fjzs',
                    title: '附件张数'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = []; 
                        if (row.pzzt!=3){
                        	 actions.push('<a class="btn btn-info btn-xs ' + '' + '" href="javascript:void(0)" onclick="account(\'' + row.pztxh + '\')"><i class="fa fa-search"></i>审核记账</a> ');
                        }else{
                        	 actions.push('<a class="btn btn-info btn-xs ' + '' + '" href="javascript:void(0)" onclick="unaccount(\'' + row.pztxh + '\')"><i class="fa fa-search"></i>撤销记账</a> ');
                        }
                        actions.push('<a class="btn btn-info btn-xs ' + '' + '" href="javascript:void(0)" onclick="pzlist(\'' + row.pztxh + '\')"><i class="fa fa-search"></i>查看凭证</a> ');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });
        
    	/* 用户状态显示 */
		function statuspzzt(row) {
		    if (row.pzzt == 0) {
    			return '未完';
    		} else  if (row.pzzt == 1) {
    			return '待审';
    		}else  if (row.pzzt == 2) {
    			return '已审';
    		}else  if (row.pzzt == 3) {
    			return '记帐';
    		}
		}
		/* 用户状态显示 */
		function statuspzlb(row) {
		    if (row.pzlb == 1) {
    			return '手工';
    		} else  if (row.pzlb == 2) {
    			return '机制';
    		}else  if (row.pzlb == 3) {
    			return '支出';
    		}else  if (row.pzlb == 4) {
    			return '结转';
    		}
		}
		function edit(){
	     	   var rows = $.table.selectColumns('pzlb');
	     	   var pzzts = $.table.selectColumns('pzzt');
	     	   if (rows.length !=1) {
					$.modal.alertWarning("请至少选择一条记录");
					return;
				}
	     	  var pzlb=rows[0]; 
	     	  if (pzlb != 1) {
	     		 $.modal.alertWarning("非手工凭证不能修改");
					return;
	    	  } 
	     	  var pzzt=pzzts[0]; 
	     	  if (pzzt==2 || pzzt==3 ) {
	     		 $.modal.alertWarning("手工凭证已审核或已记账不能修改");
				 return;
	    	 } 
	     	 $.operate.editFull();
	     	 
		}
		function remove(){
     	   var pztxh = $.table.selectColumns('pztxh');
     	   var pzbh = $.table.selectColumns('pzbh');
				$.modal.confirm("确认要删除选中的" + pzbh + "吗?", function() {
					var url = prefix + '/remove/' + pztxh;
					$.operate.submit(url, "post");
				});
		 }
		
		function checkbreak(){
				$.modal.confirm("确认要断号检查?", function() {
					var url=prefix + "/checkbreak";
					var data = { "nd": $("#nd").val(),"yf": $("#yf").val() };
					$.operate.submit(url, "post", "json", data);
				});
			}
		
		function bataccount(){
		 var rows =$.table.selectColumns("pztxh");
			if (rows.length == 0) {
				$.modal.alertWarning("请至少选择一条记录");
				return;
			}
			$.modal.confirm("确认要审核记账选中的" + rows.length + "条数据吗?", function() {
				var url=prefix + "/bataccount";
				var data = { "ids": rows.join() };
				$.operate.submit(url, "post", "json", data);
			});
		}
		function batunaccount(){
		    var rows =$.table.selectColumns("pztxh");
			if (rows.length == 0) {
				$.modal.alertWarning("请至少选择一条记录");
				return;
			}
			$.modal.confirm("确认要撤销记账选中的" + rows.length + "条数据吗?", function() {
				var url=prefix + "/batunaccount";
				var data = { "ids": rows.join() };
				$.operate.submit(url, "post", "json", data);
			});
		}
		
		function singleaccount(){
        	   var pztxh = $.table.selectColumns('pztxh');
        	   var pzbh = $.table.selectColumns('pzbh');
				$.modal.confirm("确认要审核记账选中的" + pzbh + "吗?", function() {
					var url = prefix + '/account/' + pztxh;
					$.operate.submit(url, "post");
				});
		 }
		function singleunaccount(){
			 var pztxh = $.table.selectColumns('pztxh');
      	     var pzbh = $.table.selectColumns('pzbh');
				$.modal.confirm("确认要审核记账选中的" + pzbh + "吗?", function() {
					var url = prefix + '/unaccount/' + pztxh;
					$.operate.submit(url, "post");
				});
			}
		function account(pztxh) {
			$.modal.confirm("确认要记账条记录吗?", function() {
			    var url = prefix + '/account/' + pztxh;
			    $.operate.submit(url, "post");
			});
		}
		function unaccount(pztxh) {
			$.modal.confirm("确认要记账条记录吗?", function() {
			    var url = prefix + '/unaccount/' + pztxh;
			    $.operate.submit(url, "post");
			});
		}
		function pzlist(pztxh) {
		    var url = prefix + '/pzlist/' + pztxh;
		    $.modal.openFull("查看凭证", url, '900', '540');
		}
		function add() {
		    var url = prefix + "/add";
		    $.modal.openFull("增加凭证", url, '900', '540');
		}
		function editpzbrq() {
			var pztxh = $.table.selectColumns('pztxh'); 
			layer.open({
        		type: 1,
        		area: ['400px', '230px'],
        		fix: false,
        		//不固定
        		maxmin: true,
        		shade: 0.3,
        		title: '凭证日期选择',
        		content: $('#syncTpl').html(),
        		btn: ['<i class="fa fa-check"></i>确定', '<i class="fa fa-remove"></i> 取消'],
        		// 弹层外区域关闭
        		shadeClose: true,
        		btn1: function(index, layero){
        			
        			debugger;
        			var syncdate = layero.find('#syncdate').val();
        			$.ajax({
						type : "POST",
						url : prefix + "/modifydate",
						dataType: "json",
						data : { 
							"pztxh": pztxh[0],
							"pzrq": syncdate
						},
						async : false,
						success : function(data) {
							$.modal.alertWarning(data.msg);
							$.table.search();
						}
					});
        		}
        	});
			
			
			
		}
    </script>
        <script id="syncTpl" type="text/template">
        <div class="form-group">
          <li>
               <label>修改时间：</label>
				<input class="form-control layer-date" id="syncdate" name="syncdate" placeholder="YYYY-MM-DD" onclick="laydate({istime: true, format: 'YYYY-MM-DD'})">
             	<label class="laydate-icon" ></label>
          </li>
        </div>
	</script>
</body>
</html>